$(document).ready(function(){
    
    /*//////////////////////////////////////////////////////////////////////////////
        get_job scripts:
    /////////////////////////////////////////////////////////////////////////////*/
    function hide(){
        $('#get_job_dialog_ask_the_question, #get_job_dialog_my_details, #get_job_dialog_job_information, #get_job_dialog_billing_information').hide('slow');           
    };
              
    $('.job_menu_ask_question').click(function(){
       $('.customer_details_dialog_containter').hide('slow'); 
       $('.dialog_comment').show('slow');
    });
    
    $('.my_details').click(function(){
       $('.customer_details_dialog_containter').show('slow'); 
       $('.dialog_comment').hide('slow');
    });
    
    $('.get_job_x').click(function(){
       hide();   
    });
    
    
    
    $('.job_menu_ask_question').click(function(){
        hide();
        $('#get_job_dialog_ask_the_question').show('slow');    
    });
    $('.my_details').click(function(){
        hide(); 
        $('#get_job_dialog_my_details').show('slow');
    });
    $('.job_menu_show_job_info').click(function(){
        hide(); 
        $('#get_job_dialog_job_information').show('slow');
    });
    $('.show_billing').click(function(){
        hide(); 
        $('#get_job_dialog_billing_information').show('slow');
    });

	$( "#datepicker" ).datepicker({dateFormat: 'dd-mm-yy'});
	

	
	/* 
	 * 
	 * Job Generating form:
	 * 
	 */
	$('#business_name_dropdown').change(function(){
		if ($('#business_name_dropdown option:selected').val() != 0){
			$('.customer_create_address').slideUp('fast');
		}else{
			$('.customer_create_address').slideDown('fast');
		}
	});
	
	if($('#business_name_dropdown option:selected').val() != 0){
		$('.customer_create_address').hide();
	}
	
	$('#add_item').click(function(){
		$('.inner').append('<input type="test" /><br>');	
	});


	/* 
	 * 
	 * add job form - money total:
	 * 
	 

	function money_calculation(){
		var total = 0;
		
		var $inputs = $('.money');
		$inputs.each(function() {
			if($(this).val()){
        		total += parseFloat($(this).val());
				//x = $(this).id;
				//alert (x);
        		//alert(parseFloat($(this).val()));
        	}
        
    	});
    	if(parseFloat($('#min_charge option:selected').val())>=total){
    		total= parseFloat($('#min_charge option:selected').val());
    	}
		
       
		$('#total').html(total);
		
	}
*/
	function money_calculation (){
		var total = 0;
		for (i=1;i<=10;i++){
			//ev = paymentv + i;
			ev = $('input[name=paymentv' + i +']').val();
			//ev = document.getElementsByTagName('payment')
			//eq = paymentq + i;
			eq = $('input[name=paymentq' + i +']').val();
			if (parseFloat(ev) && parseFloat(eq)){
				total += parseFloat(ev) * parseFloat(eq);
			}
			if(parseFloat(ev) && !parseFloat(eq)){
				total += parseFloat(ev);
			}
		}
		//alert ($('#rate option:selected').val());
		switch($('#rate option:selected').val()){
			case '1': rate= 50; break;
			case '2': rate= 65; break;
			case '3': rate= 60; break;
			case '4': rate= 80; break;
			case '0': rate = 0; break;
			case '5': rate= 50; break;
		}
		switch($('select[name=hours_count] option:selected').val()){
			case '0.5': total+= rate * 0.5; break;
			default: total+= rate * $('select[name=hours_count] option:selected').val(); break;
		}
		switch($('#optional	_fee option:selected').val()){
			case '1': total+= 50; break;
			case '2': total+= 30; break;
		}
		$('#total').html('Authorized total: £' + total);
		
	}

	$('input').focusout(function(){
		money_calculation();
	});
	$('input').keyup(function(){
		money_calculation();
	});
	$('select').change(function(){
		money_calculation();
	})

		money_calculation();
	/* 
	 * 
	 * 
	 * 
	 */	
		
	$().piroBox_ext({
		piro_speed : 300,
			bg_alpha : 0.5,
			piro_scroll : true // pirobox always positioned at the center of the page
	});
		
		
		
		
		
		
		
		
		
		
	


});